#include "StompedReality/Core/TypeSystem/TypeSystem.h"
#include "StompedReality/Math/Rectangle.h"
#include "StomperLib/Objects/RectPatchObject.h"
#include "StomperLib/RenderHelper.h"
#include <gl/GL.h>
CreateRegDummy ( RectPatchObject )
namespace StomperLib {

RectPatchObject::RectPatchObject( ) : StomperLib::EditorObjectInfo( )
{
  this->TypeName = "RectPatch";
  this->Pos = StompedReality::Math::Vector2( 0, 0 );
  this->Size = StompedReality::Math::Vector2( 0, 0 );
  this->PatchID = 0;
  this->TextureID = 0;
  this->TypeInfo = StompedReality::type_system::TypeSystem::GetTypeByName( "RectPatch" );
  this->PropertyInfos.push_back( StomperLib::Controls::Property::PropertyInfo( "position", "Position" ));
  this->PropertyInfos.push_back( StomperLib::Controls::Property::PropertyInfo( "size", "Size" ));
  this->PropertyInfos.push_back( StomperLib::Controls::Property::PropertyInfo( "id", "PatchID" ));
}

RectPatchObject::~RectPatchObject( )
{
}

void RectPatchObject::Draw( )
{
  StomperLib::RenderHelper::DrawRect( this->Pos, this->Pos + this->Size );
}

bool RectPatchObject::IntersectsWithMouse( StompedReality::Math::Vector2 mousePos )
{
  return StompedReality::Math::Rectangle::Contains( this->Pos, this->Size, mousePos );
}

void RectPatchObject::Translate( StompedReality::Math::Vector2 translation )
{
  this->Pos += translation;
}

int RectPatchObjectReg::registeType( )
{
  return ( int ) ( StompedReality::type_system::TypeSystem::CreateTypeInfo<RectPatchObject> ( "RectPatch" )
                   ->
                   addTypeField ( StompedReality::type_system::TypeField ( "editor name",
                                                                           &RectPatchObject::Name ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "tags",
                                                                           &RectPatchObject::Tags ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "position",
                                                                           &RectPatchObject::Pos ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "size",
                                                                           &RectPatchObject::Size ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "id",
                                                                           &RectPatchObject::PatchID ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "texture",
                                                                           &RectPatchObject::TextureID ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "texture file",
                                                                           &RectPatchObject::TextureFile ) ));
}

static int typeReg = RectPatchObjectReg::registeType( );
}
